//
//  HomeViewController.m
//  FingerUniversity
//
//  Created by vantle on 16/3/10.
//  Copyright © 2016年 vantle. All rights reserved.
//

#import "HomeViewController.h"
#import "UIColor+hexColor.h"
#import "NoticeViewController.h"
#import "UserCenterViewController.h"
#import "HelpViewController.h"
#import "ClassViewController.h"
#import <QuartzCore/QuartzCore.h>
#import "CUSFlashLabel.h"
#import "UINavigationController+push.h"
#import "MobClick.h"
#define ScreenHeight [UIScreen mainScreen].bounds.size.height
#define ScreenWidth [UIScreen mainScreen].bounds.size.width
@interface HomeViewController ()

@end

@implementation HomeViewController
- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    
    [_zhiWen removeFromSuperview];
    [_zhiWen removeFromSuperview];
    [MobClick beginLogPageView:@"HomeViewController"];//("PageOne"为页面名称，可自定义)
}
- (void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
    [MobClick endLogPageView:@"HomeViewController"];
}

- (void)viewDidLoad {
    [super viewDidLoad];

    self.view.backgroundColor=[UIColor whiteColor];
    self.navigationController.navigationBarHidden=YES;
    _headerImage=[[UIImageView alloc]initWithFrame:CGRectMake(0, 20, ScreenWidth, 44)];
    [self.view addSubview:_headerImage];
    
    UIImageView*logoImage=[[UIImageView alloc]initWithFrame:CGRectMake(15, 6, 32, 32)];
    logoImage.image=[UIImage imageNamed:@"app-logo-80"];
    logoImage.layer.cornerRadius=3;
    logoImage.clipsToBounds=YES;
    [_headerImage addSubview:logoImage];
    
    UILabel*logoName=[[UILabel alloc]init];
    logoName=[[UILabel alloc]initWithFrame:CGRectMake(logoImage.frame.origin.x+logoImage.frame.size.width+5, 10, 100, 25)];
    logoName.text=@"丹鼎教育";
    logoName.font=[UIFont systemFontOfSize:19];
    logoName.textColor=[UIColor blackColor];
    [_headerImage addSubview:logoName];
    
    [self setContent];
    
}
-(void)setContent
{
    _scrollView=[[UIScrollView alloc]initWithFrame:CGRectMake(0, 64, ScreenWidth, ScreenHeight-64)];
    _scrollView.contentSize=CGSizeMake(ScreenWidth, 90+150*4+42);
    _scrollView.bounces=NO;
    _scrollView.delegate=self;
    [self.view addSubview:_scrollView];
    
    UIImageView*bgView=[[UIImageView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, 1000)];
    bgView.image=[UIImage imageNamed:@"bg"];
    [_scrollView addSubview:bgView];
    
    UIImageView*mpHeader=[[UIImageView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, 90)];
    mpHeader.image=[UIImage imageNamed:@"mp_header_bckg"];
    [_scrollView addSubview:mpHeader];
    
    UIImageView*touImage=[[UIImageView alloc]initWithFrame:CGRectMake(15, 30, 25, 25)];
    touImage.image=[UIImage imageNamed:@"admin_icon"];
    [_scrollView addSubview:touImage];
    
    UILabel*mpHeaderLabel=[[UILabel alloc]initWithFrame:CGRectMake(touImage.frame.origin.x+touImage.frame.size.width+5, touImage.frame.origin.y-5, ScreenWidth-15-touImage.frame.size.width-15, 40)];
    
    NSUserDefaults*userDefaults=[NSUserDefaults standardUserDefaults];
   NSString*realName=[userDefaults objectForKey:@"realName"];
    mpHeaderLabel.text=[NSString stringWithFormat:@"欢迎%@同学进入课程",realName];
    mpHeaderLabel.numberOfLines=0;
    mpHeaderLabel.textColor=[UIColor colorWithRed:0.7 green:0.7 blue:0.7 alpha:1];
    mpHeaderLabel.font=[UIFont systemFontOfSize:15];
    [_scrollView addSubview:mpHeaderLabel];
    

    NSArray*buttonImageTitleArr=[[NSArray alloc]initWithObjects:@"bg_white",@"bg_kecheng",@"bg_yonghu",@"bg_set", nil];
    NSArray*buttonHeaderImageTitleArr=@[@"tuding",@"ketang_icon",@"admin_icon",@"setting_icon"];
    NSArray*buttonHeaderLabelTitleArr=@[@"通知公告",@"拇指课堂",@"用户中心",@"软件设置"];
    NSArray*buttonLabelArr=@[@"关注学校动态",@"选修兴趣课程",@"个人资料更新",@"软件帮助意见"];

    for (int i=0; i<4; i++) {
        
        UIButton*button=[UIButton buttonWithType:UIButtonTypeCustom];
        button.frame=CGRectMake(10, mpHeader.frame.origin.y+mpHeader.frame.size.height+10+160*i, ScreenWidth-20, 150);
        button.tag=100+i;
        [button addTarget:self action:@selector(buttonClick:) forControlEvents:UIControlEventTouchUpInside];
        [button setBackgroundImage:[UIImage imageNamed:buttonImageTitleArr[i]] forState:UIControlStateNormal];
        [_scrollView addSubview:button];
        
        UIImageView*buttonHeader=[[UIImageView alloc]initWithFrame:CGRectMake(20, button.frame.origin.y+8, 20, 20)];
        buttonHeader.image=[UIImage imageNamed:buttonHeaderImageTitleArr[i]];
        [_scrollView addSubview:buttonHeader];
        
        //在这里
        CUSFlashLabel*buttonHeaderLabel=[[CUSFlashLabel alloc]initWithFrame:CGRectMake(buttonHeader.frame.origin.x+buttonHeader.frame.size.width+3, button.frame.origin.y+5, 150, 25)];
        buttonHeaderLabel.text=buttonHeaderLabelTitleArr[i];
        buttonHeaderLabel.textColor=[UIColor whiteColor];
        if (i==1) {
            buttonHeaderLabel.spotlightColor=[UIColor blackColor];
            [buttonHeaderLabel startAnimating];
        }
        
        [_scrollView addSubview:buttonHeaderLabel];
        
        UILabel*buttonLabel=[[UILabel alloc]initWithFrame:CGRectMake(20, button.frame.origin.y+60, 200, 30)];
        buttonLabel.text=buttonLabelArr[i];
        
        buttonLabel.font=[UIFont systemFontOfSize:25];
        buttonLabel.textColor=[UIColor whiteColor];
        [_scrollView addSubview:buttonLabel];
        if (i==0) {
            buttonLabel.textColor=[UIColor hexFloatColor:@"FBA014"];
            buttonHeaderLabel.textColor=[UIColor blackColor];
            
            UIImageView*buttonImage=[[UIImageView alloc]initWithFrame:CGRectMake(ScreenWidth-100, button.frame.origin.y+55, 70, 80)];
            buttonImage.image=[UIImage imageNamed:@"图层-102"];
            [_scrollView addSubview:buttonImage];
        }
        else if (i==2)
        {
            UIImageView*buttonImage=[[UIImageView alloc]initWithFrame:CGRectMake(ScreenWidth-100, button.frame.origin.y+55, 70, 70)];
            buttonImage.image=[UIImage imageNamed:@"geren_pic"];
            [_scrollView addSubview:buttonImage];
        }
        
        else if (i==3)
        {
            UIImageView*buttonImage=[[UIImageView alloc]initWithFrame:CGRectMake(ScreenWidth-100, button.frame.origin.y+55, 70, 70)];
            buttonImage.image=[UIImage imageNamed:@"hander_icon"];
            [_scrollView addSubview:buttonImage];
        }
        
        
    }
    
}

-(void)buttonClick:(UIButton*)sender
{
    [_zhiWen removeFromSuperview];
    _zhiWen=[[UIImageView alloc]initWithFrame:sender.frame];
    _zhiWen.image=[UIImage imageNamed:@"zhiwen_all"];
    _zhiWen.alpha=0.5;
    [_scrollView addSubview:_zhiWen];

    if (sender.tag==100) {
        [self performSelector:@selector(pushToNotice) withObject:self afterDelay:0.01];
    }
    else if (sender.tag==101)
    {
        [self performSelector:@selector(pushToClass) withObject:self afterDelay:0.01];
    }
    else if (sender.tag==102)
    {
        [self performSelector:@selector(pushToUserView) withObject:self afterDelay:0.05];
    }
    else
    {
        [self performSelector:@selector(pushToHelpView) withObject:self afterDelay:0.05];
        
    }
}
-(void)pushToNotice
{
    NoticeViewController*noticeVC=[[NoticeViewController alloc]init];
    [self.navigationController pushViewController:noticeVC animatedWithTransition:UIViewAnimationTransitionFlipFromLeft];
//    [self.navigationController pushViewController:noticeVC animated:YES];
}
-(void)pushToClass
{
    ClassViewController*classVC=[[ClassViewController alloc]init];
    [self.navigationController pushViewController:classVC animatedWithTransition:UIViewAnimationTransitionFlipFromLeft];
//    [self.navigationController pushViewController:classVC animated:YES];
    

//    CATransition *animation = [CATransition animation];
//    [animation setDuration:0.5];
//    animation.type = @"push";
//    [animation setSubtype:kCATransitionFromBottom];
//    
//    [[classVC.view layer] addAnimation:animation forKey:@"SwitchToView"];
//    [self.navigationController pushViewController:classVC animated:NO];
}
-(void)pushToUserView
{
    UserCenterViewController*userVC=[[UserCenterViewController alloc]init];
    CATransition *animation = [CATransition animation];
    [animation setDuration:0.5];
    animation.type = @"push";
    [animation setSubtype:kCATransitionFromBottom];
    
    [[userVC.view layer] addAnimation:animation forKey:@"SwitchToView"];
    [self.navigationController pushViewController:userVC animated:NO];
}
-(void)pushToHelpView
{
    HelpViewController*helpVC=[[HelpViewController alloc]init];
    CATransition *animation = [CATransition animation];
    [animation setDuration:0.5];
    animation.type = @"push";
    [animation setSubtype:kCATransitionFromTop];
    
    [[helpVC.view layer] addAnimation:animation forKey:@"SwitchToView"];
    [self.navigationController pushViewController:helpVC animated:NO];
}
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    
    if (scrollView.contentOffset.y>0) {
        
        [_headerImage setBackgroundColor:[UIColor hexFloatColor:@"FBA014"]];
    }
    else
    {
        [_headerImage setBackgroundColor:[UIColor whiteColor]];
    }
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}



@end
